﻿using System.Windows;
using Baosight.Platform.Core.UI.Controls;
using System.Collections.Generic;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon;
using System.Windows.Threading;
using System;
using System.Windows.Controls;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.Platform.Core.ServiceModel;

namespace Baosight.ZNH.ZMCP.UI.PopWindows
{
    public partial class AddGrubWeekValidateData : EFViewCmes
    {
        public AddGrubWeekValidateData(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }


        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            switch (type)
            {
                case "insert":
                    this.fdEndDate.Value = System.DateTime.Now.ToString("yyyy-MM-dd");
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    base.Mode = OperationMode.Update;
                    break;
                case "detail":
                    base.Mode = OperationMode.Update;
                    BaseTools.EFDataFieldNotEnabled(this.InsertGrid.GetChildObjects<EFDataField>(null, true));
                    Commit.Visibility = Visibility.Collapsed;
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick(eServiceName, sender, e);
            return;
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }


        /// <summary>
        /// 工程名称选择改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdUnit_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            EFComboBox box = (sender as EFDataField).Content as EFComboBox;
            if (box.SelectedItem != null && !"".Equals(box.SelectedItem))
            {
                this.fdNo.Value = box.SelectedItem.GetType().GetProperty("fdNo").GetValue(box.SelectedItem, null);
                this.fdDepartment.Value = box.SelectedItem.GetType().GetProperty("fdDepartment").GetValue(box.SelectedItem, null);
                this.fdDepartmentId.Value = box.SelectedItem.GetType().GetProperty("fdDepartmentId").GetValue(box.SelectedItem, null);
            }
        }


        /// <summary>
        /// 施工部门
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdDepartmentId_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            EFComboBox box = (sender as EFDataField).Content as EFComboBox;
            if (box.SelectedItem != null && !"".Equals(box.SelectedItem))
            {
                this.fdDepartment.Value = box.SelectedItem.GetType().GetProperty("orgName").GetValue(box.SelectedItem, null);
            }

        }
    }
}
